package Oct_2020_BETA.part3;

import java.io.*;

public class IOUtils {
    public static void copyOf(String s1, String s2)  {
        FileInputStream f1 = null;
        try {
            f1 = new FileInputStream(s1);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        FileOutputStream f2 = null;
        try {
            f2 = new FileOutputStream(s2);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
//        修改前
            //do f2.write(f1.read()); while (f1.read()!=-1);
//        修改后
            int su = 0;
            while ((su = f1.read()) != -1) {
//
                System.out.println(su);
                f2.write(su);
            }
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            try {
                f1.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                f2.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public static void delete(File file){
        File[] p=file.listFiles();
        for (File m:p){
            if (true==m.isFile()){
                m.delete();
            }else if (true == m.isDirectory()){
                delete(m);
            }
        }
        file.delete();
    }

}
